use Data::Dumper;


my $ecs = load_ec($ARGV[0]);

#print Dumper($ecs);


open (MAPS,$ARGV[1]) or die "Cannot open $ARGV[1]";

while ($line=<MAPS>){
	chomp $line;
    my ($map,$lsec,$desc) = split ("\t",$line);
    my @listec= split (";",$lsec); 
    my $totalecs = scalar(@listec);
    my @tmpec=();
    
my $count=0;
foreach my $ec(@listec){
	$ec =~ s/ec://;
	#print $ec."\n";
	if (defined $ecs->{$ec}){
		$count++;
		push (@tmpec,$ec);
	}
}

print join ("\t", $map, $totalecs, $count, $count/$totalecs, join(";",@tmpec), $desc)."\n";

}


sub load_ec{

my $file = shift;

open (FILE,$file) or die "Cannot open $file";
my $ecs=();

while ($line=<FILE>){
	chomp $line;
	$ecs->{$line}=1;
	}
return $ecs;
}
